package com.ctsi.ssdc.mapper;

import com.ctsi.ssdc.entity.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface IndustrialIndicatorsMapper1 {

    /**
     * 分区镇规上工业总产值
     * @param year 年份
     * @param month 月份
     * @return List<SubDistrictTownIndustry>
     */
    @Select("select * from sub_district_town_industry where year(statisticalTime) = #{year} and month(statisticalTime) = #{month} order by monthOnMonth desc")
    public List<SubDistrictTownIndustry> findSubDistrictTownIndustry(@Param("year") int year, @Param("month") int month);

    /**
     * 工业总产值
     * 规上工业总产值
     * 综合能源消费量（吨标准煤）
     * 规上工业用电量（万千瓦时）
     * 万元产值能耗（吨标准煤/万元）
     * @param year 年份
     * @param indicators 指标
     * @return List<IndustrialEconomicIndicators>
     */
    @Select("select * from industrial_economic_indicators where indicators = #{indicators} and year(statisticalTime) = #{year} order by month(statisticalTime) asc")
    public List<IndustrialEconomicIndicators> findIndustrialIndicatorsByIndicators(@Param("year")int year,@Param("indicators") String indicators);

    /**
     * 高新技术产业产值
     * @param year 年份
     * @return List<HighTechIndustry>
     */
    @Select("select e1.id,e1.thisMonth,e1.accumulate,e1.monthOnMonth,e2.monthOnMonth highTechRatio,e2.thisMonth highTechRatio1,e2.accumulate highTechRatio2,e1.statisticalTime " +
            "from industrial_economic_indicators e1 left join industrial_economic_indicators e2 on year(e1.statisticalTime) = year(e2.statisticalTime) " +
            "and month(e1.statisticalTime) = month(e2.statisticalTime) where e1.indicators = '高新技术产业产值' and e2.indicators like '高新占比%' " +
            "and year(e1.statisticalTime) = #{year} order by month(e1.statisticalTime) asc")
    List<HighTechIndustry> findHighTechIndustry(@Param("year")int year);

    /**
     * 头标：当月及当月累计
     * @param year 年份
     * @param month 月份
     * @param indicators 指标
     *@return IndustrialEconomicIndicators
     */
    @Select("select * from industrial_economic_indicators where year(statisticalTime) = #{year} and month(statisticalTime) = #{month} and indicators = #{indicators} limit 1")
    IndustrialEconomicIndicators findMonthProduct(@Param("year")int year, @Param("month")int month, @Param("indicators")String indicators);

    /**
     * 规模以上工业分行业产值
     * @param year 年份
     * @param month 月份
     *@return List<SectorProduct>
     */
    @Select("select sectorName, sum(currentMonth) currentMonth, sum(currentAccumulate) currentAccumulate, sum(previousAccumulate) previousAccumulate from basic_industry where year(statisticalTime) = #{year} and month(statisticalTime) = #{month} " +
            "union select sectorName, sum(currentMonth), sum(currentAccumulate), sum(previousAccumulate) from basic_industry where year(statisticalTime) = #{year} and month(statisticalTime) = #{month}  group by sectorCode;")
    List<SectorProduct> findSectorProduct(@Param("year")int year, @Param("month")int month);
}
